package com.com.lease.web.admin.scedule;

import com.com.lease.model.entity.LeaseAgreement;
import com.com.lease.model.enums.LeaseStatus;
import com.com.lease.web.admin.service.LeaseAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class ScheduleTasks {

//    @Scheduled(cron = "* * * * * *")
//    public void test(){
//        System.out.println(new Date());
//    }

    @Autowired
    private LeaseAgreementService leaseAgreementService;

    @Scheduled(cron = "0 0 0 * * *")
    public void checkedLeaseStatus() {
        leaseAgreementService.lambdaUpdate()
                .le(LeaseAgreement::getLeaseEndDate,new Date())
                .in(LeaseAgreement::getStatus,LeaseStatus.SIGNED,LeaseStatus.WITHDRAWING)
                .set(LeaseAgreement::getStatus, LeaseStatus.EXPIRED)
                .update();
    }
}
